package com.ruoyi.echarts.controller;
import com.ruoyi.echarts.domian.AvgSalary;
import com.ruoyi.echarts.domian.Counts;
import com.ruoyi.echarts.domian.Education;
import com.ruoyi.echarts.domian.Sum;

import com.ruoyi.echarts.domian.*;

import com.ruoyi.echarts.mapper.EchartsMapper;
import com.ruoyi.echarts.service.EchartsService;
import com.ruoyi.echarts.util.JsonArrayTransformerUtil;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/echarts/echarts")
public class EchartsController {
    @Autowired
    private EchartsMapper countMapper;

    @GetMapping("/echart1")
    public Map<String,List<Counts>> getCount(){
        Map<String,List<Counts>> map=new HashMap<>();
        map.put("res",countMapper.getCount());
        return map;
    }
    @GetMapping("/echart2")
    public Map<String,List<AvgSalary>> getAvg(){
        Map<String,List<AvgSalary>> map=new HashMap<>();
        map.put("avg",countMapper.getAvg());
        return map;
    }
    /**
     * 查看自己公司所在简历的份数
     */
    @GetMapping("/echart3")
    public Map<String,List<Sum>> getCount1(){
        Map<String,List<Sum>> map=new HashMap<>();
        map.put("sum",countMapper.getCount1());
        return map;
    }
    /**
     * 各岗位占比
     */
    @GetMapping("/echarts4")
    public Map<String,List<AvgSalary>> getEducation(){
        Map<String,List<AvgSalary>> map=new HashMap<>();
        map.put("aaa",countMapper.getEducation());
        return map;
    }

    @GetMapping("/jobViewApplyStats")
    public Map<String, List<JobViewApplyStats>> getJobViewApplyStats() {
        Map<String, List<JobViewApplyStats>> map = new HashMap<>();
        map.put("jobStats", countMapper.getJobViewApplyStats());
        return map;
    }

    @GetMapping("/salaryDistributionStats")
    public Map<String, List<SalaryDistributionStats>> getSalaryDistributionStats() {
        Map<String, List<SalaryDistributionStats>> map = new HashMap<>();
        map.put("salaryStats", countMapper.getSalaryDistributionStats());
        return map;
    }


    @GetMapping("/companyJobStats")
    public Map<String, List<CompanyJobStats>> getCompanyJobStats() {
        Map<String, List<CompanyJobStats>> map = new HashMap<>();
        map.put("companyJobStats", countMapper.getCompanyJobStats());
        return map;
    }

    @GetMapping("/jobSkillStats")
    public Map<String, List<JobSkillStats>> getJobSkillStats() {
        Map<String, List<JobSkillStats>> map = new HashMap<>();
        map.put("jobSkillStats", countMapper.getJobSkillStats());
        return map;
    }


    @GetMapping("/jobAvgSalary")
    public String getJobAvgSalary(){
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jsonArrayString=gson.toJson(countMapper.getAvgSalaryCity());
        JSONArray transformer= JsonArrayTransformerUtil.transformer(jsonArrayString);
        return transformer.toString();
    }
    @GetMapping("/jobExperience")
    public String getJobExperience(){
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jsonArrayString=gson.toJson(countMapper.getJobExperience());
        JSONArray transformer= JsonArrayTransformerUtil.transformer2(jsonArrayString);
        return transformer.toString();
    }
    @GetMapping("/jobEducation")
    public String getJobEducation(){
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jsonArrayString=gson.toJson(countMapper.getJobEducation());
        JSONArray transformer= JsonArrayTransformerUtil.transformer3(jsonArrayString);
        return transformer.toString();
    }


    @GetMapping("/filteredJobViewApplyStats")
    public Map<String, List<JobViewApplyStats>> getFilteredJobViewApplyStats() {
        Map<String, List<JobViewApplyStats>> map = new HashMap<>();
        map.put("jobStats", countMapper.getJobViewApplyStatsFiltered());
        return map;
    }

    @GetMapping("/filteredSalaryDistributionStats")
    public Map<String, List<SalaryDistributionStats>> getFilteredSalaryDistributionStats() {
        Map<String, List<SalaryDistributionStats>> map = new HashMap<>();
        map.put("salaryStats", countMapper.getSalaryDistributionStatsFiltered());
        return map;
    }

    @GetMapping("/filteredCompanyJobStats")
    public Map<String, List<CompanyJobStats>> getFilteredCompanyJobStats() {
        Map<String, List<CompanyJobStats>> map = new HashMap<>();
        map.put("companyJobStats", countMapper.getCompanyJobStatsFiltered());
        return map;
    }

    @GetMapping("/filteredJobSkillStats")
    public Map<String, List<JobSkillStats>> getFilteredJobSkillStats() {
        Map<String, List<JobSkillStats>> map = new HashMap<>();
        map.put("jobSkillStats", countMapper.getJobSkillStatsFiltered());
        return map;
    }

    @GetMapping("/filteredInterviewStats")
    public Map<String, List<InterviewStats>> getFilteredInterviewStats() {
        Map<String, List<InterviewStats>> map = new HashMap<>();
        map.put("interviewStats", countMapper.getInterviewStatsFiltered());
        return map;
    }

    @GetMapping("/filteredEducationStats")
    public Map<String, List<AvgSalary>> getFilteredEducationStats() {
        Map<String, List<AvgSalary>> map = new HashMap<>();
        map.put("educationStats", countMapper.getEducationFiltered());
        return map;
    }

    @GetMapping("/filteredCompanyStats") // 新的接口路径
    public Map<String, List<Counts>> getCountForYangShi() {
        Map<String, List<Counts>> map = new HashMap<>();
        map.put("res", countMapper.getCountForYangShi()); // 调用修改后的Mapper方法
        return map;
    }

}
